<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>CmdMessenger: D:/My Documents/Github/Arduino/Own Arduino libraries/CmdMessenger/Arduino-CmdMessenger/CmdMessenger.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">CmdMessenger
   &#160;<span id="projectnumber">4.0.0</span>
   </div>
   <div id="projectbrief">CmdMessenger is a messaging library for the Arduino Platform. It has uses the serial port as its transport layer</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">D:/My Documents/Github/Arduino/Own Arduino libraries/CmdMessenger/Arduino-CmdMessenger/CmdMessenger.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">  CmdMessenger - library that provides command based messaging</span>
<a name="l00003"></a>00003 <span class="comment"></span>
<a name="l00004"></a>00004 <span class="comment">  Permission is hereby granted, free of charge, to any person obtaining</span>
<a name="l00005"></a>00005 <span class="comment">  a copy of this software and associated documentation files (the</span>
<a name="l00006"></a>00006 <span class="comment">  &quot;Software&quot;), to deal in the Software without restriction, including</span>
<a name="l00007"></a>00007 <span class="comment">  without limitation the rights to use, copy, modify, merge, publish,</span>
<a name="l00008"></a>00008 <span class="comment">  distribute, sublicense, and/or sell copies of the Software, and to</span>
<a name="l00009"></a>00009 <span class="comment">  permit persons to whom the Software is furnished to do so, subject to</span>
<a name="l00010"></a>00010 <span class="comment">  the following conditions:</span>
<a name="l00011"></a>00011 <span class="comment"></span>
<a name="l00012"></a>00012 <span class="comment">  The above copyright notice and this permission notice shall be</span>
<a name="l00013"></a>00013 <span class="comment">  included in all copies or substantial portions of the Software.</span>
<a name="l00014"></a>00014 <span class="comment"></span>
<a name="l00015"></a>00015 <span class="comment">  THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,</span>
<a name="l00016"></a>00016 <span class="comment">  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span>
<a name="l00017"></a>00017 <span class="comment">  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND</span>
<a name="l00018"></a>00018 <span class="comment">  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE</span>
<a name="l00019"></a>00019 <span class="comment">  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION</span>
<a name="l00020"></a>00020 <span class="comment">  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION</span>
<a name="l00021"></a>00021 <span class="comment">  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span>
<a name="l00022"></a>00022 <span class="comment"></span>
<a name="l00023"></a>00023 <span class="comment">  */</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#ifndef CmdMessenger_h</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define CmdMessenger_h</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;inttypes.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#if ARDUINO &gt;= 100</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include &lt;Arduino.h&gt;</span> 
<a name="l00031"></a>00031 <span class="preprocessor">#else</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include &lt;WProgram.h&gt;</span> 
<a name="l00033"></a>00033 <span class="preprocessor">#endif</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span>
<a name="l00035"></a>00035 <span class="comment">//#include &quot;Stream.h&quot;</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span>
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039     <span class="comment">// callback functions always follow the signature: void cmd(void);</span>
<a name="l00040"></a>00040     <span class="keyword">typedef</span> void(*messengerCallbackFunction) (void);
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="preprocessor">#define MAXCALLBACKS        50   // The maximum number of commands   (default: 50)</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define MESSENGERBUFFERSIZE 64   // The length of the commandbuffer  (default: 64)</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#define MAXSTREAMBUFFERSIZE 512  // The length of the streambuffer   (default: 64)</span>
<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#define DEFAULT_TIMEOUT     5000 // Time out on unanswered messages. (default: 5s)</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span>
<a name="l00048"></a>00048 <span class="comment">// Message States</span>
<a name="l00049"></a>00049 <span class="keyword">enum</span>
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051     kProccesingMessage,            <span class="comment">// Message is being received, not reached command separator</span>
<a name="l00052"></a>00052     kEndOfMessage,               <span class="comment">// Message is fully received, reached command separator</span>
<a name="l00053"></a>00053     kProcessingArguments,            <span class="comment">// Message is received, arguments are being read parsed</span>
<a name="l00054"></a>00054 };
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="preprocessor">#define white_space(c) ((c) == &#39; &#39; || (c) == &#39;\t&#39;)</span>
<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define valid_digit(c) ((c) &gt;= &#39;0&#39; &amp;&amp; (c) &lt;= &#39;9&#39;)</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span>
<a name="l00059"></a><a class="code" href="class_cmd_messenger.html">00059</a> <span class="keyword">class </span><a class="code" href="class_cmd_messenger.html">CmdMessenger</a>
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061 <span class="keyword">private</span>:
<a name="l00062"></a>00062     <span class="comment">// **** Private variables *** </span>
<a name="l00063"></a>00063 
<a name="l00064"></a>00064     <span class="keywordtype">bool</span>    startCommand;            <span class="comment">// Indicates if sending of a command is underway</span>
<a name="l00065"></a>00065     uint8_t lastCommandId;          <span class="comment">// ID of last received command </span>
<a name="l00066"></a>00066     uint8_t bufferIndex;              <span class="comment">// Index where to write data in buffer</span>
<a name="l00067"></a>00067     uint8_t bufferLength;             <span class="comment">// Is set to MESSENGERBUFFERSIZE</span>
<a name="l00068"></a>00068     uint8_t bufferLastIndex;          <span class="comment">// The last index of the buffer</span>
<a name="l00069"></a>00069     <span class="keywordtype">char</span> ArglastChar;                 <span class="comment">// Bookkeeping of argument escape char </span>
<a name="l00070"></a>00070     <span class="keywordtype">char</span> CmdlastChar;                 <span class="comment">// Bookkeeping of command escape char </span>
<a name="l00071"></a>00071     <span class="keywordtype">bool</span> pauseProcessing;             <span class="comment">// pauses processing of new commands, during sending</span>
<a name="l00072"></a>00072     <span class="keywordtype">bool</span> print_newlines;              <span class="comment">// Indicates if \r\n should be added after send command</span>
<a name="l00073"></a>00073     <span class="keywordtype">char</span> commandBuffer[MESSENGERBUFFERSIZE]; <span class="comment">// Buffer that holds the data</span>
<a name="l00074"></a>00074     <span class="keywordtype">char</span> streamBuffer[MAXSTREAMBUFFERSIZE]; <span class="comment">// Buffer that holds the data</span>
<a name="l00075"></a>00075     uint8_t messageState;             <span class="comment">// Current state of message processing</span>
<a name="l00076"></a>00076     <span class="keywordtype">bool</span> dumped;                      <span class="comment">// Indicates if last argument has been externally read </span>
<a name="l00077"></a>00077     <span class="keywordtype">bool</span> ArgOk;                     <span class="comment">// Indicated if last fetched argument could be read</span>
<a name="l00078"></a>00078     <span class="keywordtype">char</span> *current;                    <span class="comment">// Pointer to current buffer position</span>
<a name="l00079"></a>00079     <span class="keywordtype">char</span> *last;                       <span class="comment">// Pointer to previous buffer position</span>
<a name="l00080"></a>00080     <span class="keywordtype">char</span> prevChar;                    <span class="comment">// Previous char (needed for unescaping)</span>
<a name="l00081"></a>00081     Stream *comms;                    <span class="comment">// Serial data stream</span>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083     <span class="keywordtype">char</span> command_separator;           <span class="comment">// Character indicating end of command (default: &#39;;&#39;)</span>
<a name="l00084"></a>00084     <span class="keywordtype">char</span> field_separator;               <span class="comment">// Character indicating end of argument (default: &#39;,&#39;)</span>
<a name="l00085"></a>00085     <span class="keywordtype">char</span> escape_character;          <span class="comment">// Character indicating escaping of special chars</span>
<a name="l00086"></a>00086 
<a name="l00087"></a>00087     messengerCallbackFunction default_callback;            <span class="comment">// default callback function  </span>
<a name="l00088"></a>00088     messengerCallbackFunction callbackList[MAXCALLBACKS];  <span class="comment">// list of attached callback functions </span>
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 
<a name="l00091"></a>00091     <span class="comment">// **** Initialize ****</span>
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     <span class="keywordtype">void</span> init(Stream &amp; comms, <span class="keyword">const</span> <span class="keywordtype">char</span> fld_separator, <span class="keyword">const</span> <span class="keywordtype">char</span> cmd_separator, <span class="keyword">const</span> <span class="keywordtype">char</span> esc_character);
<a name="l00094"></a>00094     <span class="keywordtype">void</span> reset();
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     <span class="comment">// **** Command processing ****</span>
<a name="l00097"></a>00097 
<a name="l00098"></a>00098     <span class="keyword">inline</span> uint8_t processLine(<span class="keywordtype">char</span> serialChar) __attribute__((always_inline));
<a name="l00099"></a>00099     <span class="keyword">inline</span> <span class="keywordtype">void</span> handleMessage() __attribute__((always_inline));
<a name="l00100"></a>00100     <span class="keyword">inline</span> <span class="keywordtype">bool</span> blockedTillReply(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout = DEFAULT_TIMEOUT, byte ackCmdId = 1) __attribute__((always_inline));
<a name="l00101"></a>00101     <span class="keyword">inline</span> <span class="keywordtype">bool</span> checkForAck(byte AckCommand) __attribute__((always_inline));
<a name="l00102"></a>00102 
<a name="l00103"></a>00103     <span class="comment">// **** Command sending ****</span>
<a name="l00104"></a>00104 
<a name="l00108"></a>00108     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt;
<a name="l00109"></a>00109     <span class="keywordtype">void</span> writeBin(<span class="keyword">const</span> T &amp; value)
<a name="l00110"></a>00110     {
<a name="l00111"></a>00111         <span class="keyword">const</span> byte *bytePointer = (<span class="keyword">const</span> byte *)(<span class="keyword">const</span> <span class="keywordtype">void</span> *)&amp;value;
<a name="l00112"></a>00112         <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(value); i++)
<a name="l00113"></a>00113         {
<a name="l00114"></a>00114             printEsc(*bytePointer);
<a name="l00115"></a>00115             bytePointer++;
<a name="l00116"></a>00116         }
<a name="l00117"></a>00117     }
<a name="l00118"></a>00118 
<a name="l00119"></a>00119     <span class="comment">// **** Command receiving ****</span>
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     <span class="keywordtype">int</span> findNext(<span class="keywordtype">char</span> *str, <span class="keywordtype">char</span> delim);
<a name="l00122"></a>00122 
<a name="l00126"></a>00126     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt;
<a name="l00127"></a>00127     T readBin(<span class="keywordtype">char</span> *str)
<a name="l00128"></a>00128     {
<a name="l00129"></a>00129         T value;
<a name="l00130"></a>00130         <a class="code" href="class_cmd_messenger.html#a604709c8cac00ddb3638f1163a23712a">unescape</a>(str);
<a name="l00131"></a>00131         byte *bytePointer = (byte *)(<span class="keyword">const</span> <span class="keywordtype">void</span> *)&amp;value;
<a name="l00132"></a>00132         <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(value); i++)
<a name="l00133"></a>00133         {
<a name="l00134"></a>00134             *bytePointer = str[i];
<a name="l00135"></a>00135             bytePointer++;
<a name="l00136"></a>00136         }
<a name="l00137"></a>00137         <span class="keywordflow">return</span> value;
<a name="l00138"></a>00138     }
<a name="l00139"></a>00139 
<a name="l00140"></a>00140     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt;
<a name="l00141"></a>00141     T empty()
<a name="l00142"></a>00142     {
<a name="l00143"></a>00143         T value;
<a name="l00144"></a>00144         byte *bytePointer = (byte *)(<span class="keyword">const</span> <span class="keywordtype">void</span> *)&amp;value;
<a name="l00145"></a>00145         <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(value); i++)
<a name="l00146"></a>00146         {
<a name="l00147"></a>00147             *bytePointer = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00148"></a>00148             bytePointer++;
<a name="l00149"></a>00149         }
<a name="l00150"></a>00150         <span class="keywordflow">return</span> value;
<a name="l00151"></a>00151     }
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     <span class="comment">// **** Escaping tools ****</span>
<a name="l00154"></a>00154 
<a name="l00155"></a>00155     <span class="keywordtype">char</span> *split_r(<span class="keywordtype">char</span> *str, <span class="keyword">const</span> <span class="keywordtype">char</span> delim, <span class="keywordtype">char</span> **nextp);
<a name="l00156"></a>00156     <span class="keywordtype">bool</span> isEscaped(<span class="keywordtype">char</span> *currChar, <span class="keyword">const</span> <span class="keywordtype">char</span> escapeChar, <span class="keywordtype">char</span> *lastChar);
<a name="l00157"></a>00157 
<a name="l00158"></a>00158     <span class="keywordtype">void</span> printEsc(<span class="keywordtype">char</span> *str);
<a name="l00159"></a>00159     <span class="keywordtype">void</span> printEsc(<span class="keywordtype">char</span> str);
<a name="l00160"></a>00160 
<a name="l00161"></a>00161 <span class="keyword">public</span>:
<a name="l00162"></a>00162 
<a name="l00163"></a>00163     <span class="comment">// ****** Public functions ******</span>
<a name="l00164"></a>00164 
<a name="l00165"></a>00165     <span class="comment">// **** Initialization ****</span>
<a name="l00166"></a>00166 
<a name="l00167"></a>00167     <a class="code" href="class_cmd_messenger.html#a4c54e812e051d55bd3a5fd61dfd085d9">CmdMessenger</a>(Stream &amp; comms, <span class="keyword">const</span> <span class="keywordtype">char</span> fld_separator = <span class="charliteral">&#39;,&#39;</span>,
<a name="l00168"></a>00168         <span class="keyword">const</span> <span class="keywordtype">char</span> cmd_separator = <span class="charliteral">&#39;;&#39;</span>,
<a name="l00169"></a>00169         <span class="keyword">const</span> <span class="keywordtype">char</span> esc_character = <span class="charliteral">&#39;/&#39;</span>);
<a name="l00170"></a>00170 
<a name="l00171"></a>00171     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a35ed803209fdad21fa38d0ef98f0f3a9">printLfCr</a>(<span class="keywordtype">bool</span> addNewLine = <span class="keyword">true</span>);
<a name="l00172"></a>00172     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#af29176b430fbc58c7f0289acc67c1708">attach</a>(messengerCallbackFunction newFunction);
<a name="l00173"></a>00173     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#af29176b430fbc58c7f0289acc67c1708">attach</a>(byte msgId, messengerCallbackFunction newFunction);
<a name="l00174"></a>00174 
<a name="l00175"></a>00175     <span class="comment">// **** Command processing ****</span>
<a name="l00176"></a>00176 
<a name="l00177"></a>00177     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#ad4de9df5669b1ba98dc553ad20723682">feedinSerialData</a>();
<a name="l00178"></a>00178     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#abe96932ce5e813a7ef406280c922e191">next</a>();
<a name="l00179"></a>00179     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#ace5e703c0bf2c054bd95c7ce99a5c30d">available</a>();
<a name="l00180"></a>00180     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#a3207f1df2e236710cfeda5bd0cce25a9">isArgOk</a>();
<a name="l00181"></a>00181     uint8_t <a class="code" href="class_cmd_messenger.html#a5b6f1f973959c7ca1f88b8e2fd78b5c1">commandID</a>();
<a name="l00182"></a>00182 
<a name="l00183"></a>00183     <span class="comment">// ****  Command sending ****</span>
<a name="l00184"></a>00184 
<a name="l00189"></a>00189     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt;
<a name="l00190"></a><a class="code" href="class_cmd_messenger.html#a87716ae89670a9429b09b594cbde686e">00190</a>     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#a87716ae89670a9429b09b594cbde686e">sendCmd</a>(byte cmdId, T arg, <span class="keywordtype">bool</span> reqAc = <span class="keyword">false</span>, byte ackCmdId = 1,
<a name="l00191"></a>00191         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout = DEFAULT_TIMEOUT)
<a name="l00192"></a>00192     {
<a name="l00193"></a>00193         <span class="keywordflow">if</span> (!startCommand) {
<a name="l00194"></a>00194             <a class="code" href="class_cmd_messenger.html#a7d942bf8759c5b4bd91ef66d12c5e76f">sendCmdStart</a>(cmdId);
<a name="l00195"></a>00195             <a class="code" href="class_cmd_messenger.html#a516cacd12a4e1b19d63614c4d7964105">sendCmdArg</a>(arg);
<a name="l00196"></a>00196             <span class="keywordflow">return</span> <a class="code" href="class_cmd_messenger.html#a9bcad5dbd7432ee49fa9849767c0090d">sendCmdEnd</a>(reqAc, ackCmdId, timeout);
<a name="l00197"></a>00197         }
<a name="l00198"></a>00198         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00199"></a>00199     }
<a name="l00200"></a>00200 
<a name="l00205"></a>00205     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt;
<a name="l00206"></a><a class="code" href="class_cmd_messenger.html#a6f1c1843fee27f53a5f275f4bbeb062a">00206</a>     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#a6f1c1843fee27f53a5f275f4bbeb062a">sendBinCmd</a>(byte cmdId, T arg, <span class="keywordtype">bool</span> reqAc = <span class="keyword">false</span>, byte ackCmdId = 1,
<a name="l00207"></a>00207         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout = DEFAULT_TIMEOUT)
<a name="l00208"></a>00208     {
<a name="l00209"></a>00209         <span class="keywordflow">if</span> (!startCommand) {
<a name="l00210"></a>00210             <a class="code" href="class_cmd_messenger.html#a7d942bf8759c5b4bd91ef66d12c5e76f">sendCmdStart</a>(cmdId);
<a name="l00211"></a>00211             <a class="code" href="class_cmd_messenger.html#a4bc93989ec5e50712c728558664bf458">sendCmdBinArg</a>(arg);
<a name="l00212"></a>00212             <span class="keywordflow">return</span> <a class="code" href="class_cmd_messenger.html#a9bcad5dbd7432ee49fa9849767c0090d">sendCmdEnd</a>(reqAc, ackCmdId, timeout);
<a name="l00213"></a>00213         }
<a name="l00214"></a>00214         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00215"></a>00215     }
<a name="l00216"></a>00216 
<a name="l00217"></a>00217     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#a87716ae89670a9429b09b594cbde686e">sendCmd</a>(byte cmdId);
<a name="l00218"></a>00218     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#a87716ae89670a9429b09b594cbde686e">sendCmd</a>(byte cmdId, <span class="keywordtype">bool</span> reqAc, byte ackCmdId);
<a name="l00219"></a>00219     <span class="comment">// **** Command sending with multiple arguments ****</span>
<a name="l00220"></a>00220 
<a name="l00221"></a>00221     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a7d942bf8759c5b4bd91ef66d12c5e76f">sendCmdStart</a>(byte cmdId);
<a name="l00222"></a>00222     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#ad5a942deaa56cd35898eea38903f820e">sendCmdEscArg</a>(<span class="keywordtype">char</span> *arg);
<a name="l00223"></a>00223     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a7e19e93d95c001d9b0538c19f6b0c17c">sendCmdfArg</a>(<span class="keywordtype">char</span> *fmt, ...);
<a name="l00224"></a>00224     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#a9bcad5dbd7432ee49fa9849767c0090d">sendCmdEnd</a>(<span class="keywordtype">bool</span> reqAc = <span class="keyword">false</span>, byte ackCmdId = 1, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> timeout = DEFAULT_TIMEOUT);
<a name="l00225"></a>00225 
<a name="l00230"></a><a class="code" href="class_cmd_messenger.html#a516cacd12a4e1b19d63614c4d7964105">00230</a>     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt; <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a516cacd12a4e1b19d63614c4d7964105">sendCmdArg</a>(T arg)
<a name="l00231"></a>00231     {
<a name="l00232"></a>00232         <span class="keywordflow">if</span> (startCommand) {
<a name="l00233"></a>00233             comms-&gt;print(field_separator);
<a name="l00234"></a>00234             comms-&gt;print(arg);
<a name="l00235"></a>00235         }
<a name="l00236"></a>00236     }
<a name="l00237"></a>00237 
<a name="l00242"></a><a class="code" href="class_cmd_messenger.html#ad170573e370452a379bf3649e14b0162">00242</a>     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt; <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a516cacd12a4e1b19d63614c4d7964105">sendCmdArg</a>(T arg, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)
<a name="l00243"></a>00243     {
<a name="l00244"></a>00244         <span class="keywordflow">if</span> (startCommand) {
<a name="l00245"></a>00245             comms-&gt;print(field_separator);
<a name="l00246"></a>00246             comms-&gt;print(arg, n);
<a name="l00247"></a>00247         }
<a name="l00248"></a>00248     }
<a name="l00249"></a>00249 
<a name="l00254"></a>00254     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#ac9945e206834468406c1fe447b8859c3">sendCmdSciArg</a>(<span class="keywordtype">double</span> arg, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n = 6);
<a name="l00255"></a>00255 
<a name="l00256"></a>00256 
<a name="l00261"></a><a class="code" href="class_cmd_messenger.html#a4bc93989ec5e50712c728558664bf458">00261</a>     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt; <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a4bc93989ec5e50712c728558664bf458">sendCmdBinArg</a>(T arg)
<a name="l00262"></a>00262     {
<a name="l00263"></a>00263         <span class="keywordflow">if</span> (startCommand) {
<a name="l00264"></a>00264             comms-&gt;print(field_separator);
<a name="l00265"></a>00265             writeBin(arg);
<a name="l00266"></a>00266         }
<a name="l00267"></a>00267     }
<a name="l00268"></a>00268 
<a name="l00269"></a>00269     <span class="comment">// **** Command receiving ****</span>
<a name="l00270"></a>00270     <span class="keywordtype">bool</span> <a class="code" href="class_cmd_messenger.html#a0118332c0880f3f634bc458c556d8d7a">readBoolArg</a>();
<a name="l00271"></a>00271     int16_t <a class="code" href="class_cmd_messenger.html#a84fbb4b3c6922a3b94a352d5fc16c1e0">readInt16Arg</a>();
<a name="l00272"></a>00272     int32_t <a class="code" href="class_cmd_messenger.html#a148b1a72ad25d0afc7fd393a6d30312c">readInt32Arg</a>();
<a name="l00273"></a>00273     <span class="keywordtype">char</span> <a class="code" href="class_cmd_messenger.html#aa7c2ac636d59660e17ed4b7515df25ba">readCharArg</a>();
<a name="l00274"></a>00274     <span class="keywordtype">float</span> <a class="code" href="class_cmd_messenger.html#ada11d87584542951837b50cc2ba1ecbc">readFloatArg</a>();
<a name="l00275"></a>00275     <span class="keywordtype">double</span> <a class="code" href="class_cmd_messenger.html#a5d8f92696a18b428a72426de02ae466c">readDoubleArg</a>();
<a name="l00276"></a>00276     <span class="keywordtype">char</span> *<a class="code" href="class_cmd_messenger.html#a593dd2763f6c817447de5cd38adfa1f4">readStringArg</a>();
<a name="l00277"></a>00277     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a7757a31834d68e79845490006f20e8c2">copyStringArg</a>(<span class="keywordtype">char</span> *<span class="keywordtype">string</span>, uint8_t size);
<a name="l00278"></a>00278     uint8_t <a class="code" href="class_cmd_messenger.html#a4571c8ce449826dceeac5417efa16e78">compareStringArg</a>(<span class="keywordtype">char</span> *<span class="keywordtype">string</span>);
<a name="l00279"></a>00279 
<a name="l00283"></a><a class="code" href="class_cmd_messenger.html#a43a6cff1235a0b39c81b41371f3fff76">00283</a>     <span class="keyword">template</span> &lt; <span class="keyword">class</span> T &gt; T <a class="code" href="class_cmd_messenger.html#a43a6cff1235a0b39c81b41371f3fff76">readBinArg</a>()
<a name="l00284"></a>00284     {
<a name="l00285"></a>00285         <span class="keywordflow">if</span> (<a class="code" href="class_cmd_messenger.html#abe96932ce5e813a7ef406280c922e191">next</a>()) {
<a name="l00286"></a>00286             dumped = <span class="keyword">true</span>;
<a name="l00287"></a>00287             <span class="keywordflow">return</span> readBin &lt; T &gt;(current);
<a name="l00288"></a>00288         }
<a name="l00289"></a>00289         <span class="keywordflow">else</span> {
<a name="l00290"></a>00290             <span class="keywordflow">return</span> empty &lt; T &gt;();
<a name="l00291"></a>00291         }
<a name="l00292"></a>00292     }
<a name="l00293"></a>00293 
<a name="l00294"></a>00294     <span class="comment">// **** Escaping tools ****</span>
<a name="l00295"></a>00295 
<a name="l00296"></a>00296     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a604709c8cac00ddb3638f1163a23712a">unescape</a>(<span class="keywordtype">char</span> *fromChar);
<a name="l00297"></a>00297     <span class="keywordtype">void</span> <a class="code" href="class_cmd_messenger.html#a7c8e45cdef09dd8c551aa3a2a2254561">printSci</a>(<span class="keywordtype">double</span> f, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> digits);
<a name="l00298"></a>00298 
<a name="l00299"></a>00299 
<a name="l00300"></a>00300 };
<a name="l00301"></a>00301 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 24 2015 23:15:50 for CmdMessenger by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
